package layer
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.system.Security;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	import flash3.net.INetConnect;
	import flash3.net.NetFacade;
	import flash3.net.MsgPacket;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.ProgressEvent;
	import net.LobbyLoginGroup;
	
	public class Login extends Sprite implements INetConnect
	{
		private var mImgBg:imgLogin;
		private var mEdtUsr:TextField;
		private var mEdtPwd:TextField;
		
		public function Login()
		{
			super();
			
			mImgBg = new imgLogin;
			addChild(mImgBg); 
			
			mEdtUsr = new TextField;
			mEdtUsr.x = 389+98;
			mEdtUsr.y = 422-103;
			mEdtUsr.width = 191-20;
			mEdtUsr.height = 34;
			mEdtUsr.maxChars = 18;
			mEdtUsr.textColor = 0xffffffff;
			var textFormat:TextFormat = new TextFormat;
			textFormat.font = "微软雅黑";
			textFormat.size = 20;
			mEdtUsr.defaultTextFormat = textFormat;
			mEdtUsr.type = TextFieldType.INPUT;
			addChild(mEdtUsr);
			
			mEdtPwd = new TextField;
			mEdtPwd.x = 389+98;
			mEdtPwd.y = 492-109;
			mEdtPwd.width = 191-20;
			mEdtPwd.height = 34;
			mEdtPwd.maxChars = 18;
			mEdtPwd.textColor = 0xffffffff;
			textFormat = new TextFormat;
			textFormat.font = "微软雅黑";
			textFormat.size = 20;
			mEdtPwd.defaultTextFormat = textFormat;
			mEdtPwd.type = TextFieldType.INPUT;
			mEdtPwd.displayAsPassword = true;
			addChild(mEdtPwd);
			
			mEdtUsr.text = "111111";
			mEdtPwd.text = "96e79218965eb72c92a549dd5a330112";
			
			mImgBg.mBtnLogin.addEventListener(MouseEvent.CLICK, onClickLogin);
		}
		
		public function onClickLogin(evt:MouseEvent):void
		{
			Security.loadPolicyFile("xmlsocket://58.56.19.126:9000");
			NetFacade.i.connect("58.56.19.126", 9000, this);
		}
		
		public function onConnectSucceed(evt:Event):void
		{
			trace("连接成功");
			NetFacade.i.acall(LobbyLoginGroup.MDM_GP_LOGON,LobbyLoginGroup.SUB_GP_LOGON_SUCCESS,{call:onNetLoginSuccess});
			NetFacade.i.send(LobbyLoginGroup.MDM_GP_LOGON, LobbyLoginGroup.SUB_GP_LOGON_ACCOUNTS, [mEdtUsr.text, mEdtPwd.text], {call:netRequestLogin});
		}
		public function onIOError(evt:IOErrorEvent):void
		{
			trace("IO错误");
		}
		public function onSecurityError(evt:SecurityErrorEvent):void
		{
			trace("安全错误");
		}
		public function onConnectClose(evt:Event):void
		{
			trace("连接关闭");
		}
		public function netRequestLogin(packet:MsgPacket):void
		{
			trace("请求登录");
		}
		public function onNetLoginSuccess(packet:MsgPacket):void
		{
			trace("请求登录回复");
		}
	}
}